package top.xxyu.file.service.impl;

import java.util.Date;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import top.xxyu.app.mapper.FileMapper;
import top.xxyu.app.pojo.File;
import top.xxyu.context.LocalContext;
import top.xxyu.file.service.IFileService;

@Service("fileService")
public class FileServiceImpl implements IFileService {

	@Autowired
	private FileMapper fileMapper;

	@Override
	public int deleteByPrimaryKey(String id) {
		return fileMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(File record) {
		// TODO Auto-generated method stub
		return fileMapper.insert(record);
	}

	@Override
	public int insertSelective(File record) {
		// TODO Auto-generated method stub
		return fileMapper.insertSelective(record);
	}

	@Override
	public File selectByPrimaryKey(String id) {
		// TODO Auto-generated method stub
		return fileMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(File record) {
		// TODO Auto-generated method stub
		return fileMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(File record) {
		// TODO Auto-generated method stub
		return fileMapper.updateByPrimaryKey(record);
	}

	@Override
	public String insertUpload(String name, String realName, String path) {
		File file = new File();
		file.setCreateby(LocalContext.getCurrentUser().getUsername());
		file.setCreatedate(new Date());
		file.setName(name);
		file.setRname(realName);
		file.setPath(path);
		
		file.setId(UUID.randomUUID().toString());
		int num = insertSelective(file);
		
		return num > 0 ? file.getId() : "";
	}

	@Override
	public String insertUpload(String path) {
		File file = new File();
		file.setCreateby(LocalContext.getCurrentUser().getUsername());
		file.setCreatedate(new Date());

		file.setId(UUID.randomUUID().toString());
		int num = insertSelective(file);
		
		return num > 0 ? file.getId() : "";
	}

}
